import Taro from '@tarojs/taro-rn';
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Text, Image } from "@tarojs/components-rn";
import issueStyleSheet from "./issue_styles";
import icon_19 from '../../assets/img/icon_19.png';
import icon_20 from '../../assets/img/icon_20.png';
import icon_21 from '../../assets/img/icon_21.png';
import icon_22 from '../../assets/img/icon_22.png';
// 发布页
var _styleSheet = issueStyleSheet;

function _getClassName() {
  var className = [];
  var args = arguments[0];
  var type = Object.prototype.toString.call(args).slice(8, -1).toLowerCase();

  if (type === 'string') {
    args = args.trim();
    args && className.push(args);
  } else if (type === 'array') {
    args.forEach(function (cls) {
      cls = _getClassName(cls).trim();
      cls && className.push(cls);
    });
  } else if (type === 'object') {
    for (var k in args) {
      k = k.trim();

      if (k && args.hasOwnProperty(k) && args[k]) {
        className.push(k);
      }
    }
  }

  return className.join(' ').trim();
}

function _getStyle(classNameExpression) {
  var className = _getClassName(classNameExpression);

  var classNameArr = className.split(/\s+/);
  var style = [];

  if (classNameArr.length === 1) {
    style.push(_styleSheet[classNameArr[0].trim()]);
  } else {
    classNameArr.forEach(function (cls) {
      style.push(_styleSheet[cls.trim()]);
    });
  }

  return style;
}

let Issue = class Issue extends Component {
  constructor() {
    super();
    this.state = {
      contentShow: false
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '发布' });
  }
  handleClick() {
    this.setState({
      contentShow: !this.state.contentShow
    });
  }
  render() {
    return <View>
        {console.log(this.state.contentShow)}
        <View onClick={this.handleClick.bind(this)} style={_styleSheet["btn"]}>控制按钮</View>
        <View style={_getStyle(this.state.contentShow ? 'issue-wrap issue-wrap-show' : 'issue-wrap')}>
          <View style={_styleSheet["content"]}>
            <View style={_styleSheet["item"]}>
              <Image src={icon_19} style={_styleSheet["item-icon"]} />
              <Text style={_styleSheet["item-title"]}>发布需求</Text>
            </View>
            <View style={_styleSheet["item"]}>
              <Image src={icon_20} style={_styleSheet["item-icon"]} />
              <Text style={_styleSheet["item-title"]}>提供服务</Text>
            </View>
            <View style={_styleSheet["item"]}>
              <Image src={icon_21} style={_styleSheet["item-icon"]} />
              <Text style={_styleSheet["item-title"]}>发布职位</Text>
            </View>
            <View style={_styleSheet["item"]}>
              <Image src={icon_22} style={_styleSheet["item-icon"]} />
              <Text style={_styleSheet["item-title"]}>发布简历</Text>
            </View>
          </View>
        </View>
      </View>;
  }
};

export default Issue;